#include "Assert.h"

#include <string>
 
std::ostream& operator << (std::ostream& out, const AssertFailedException ex) {
	out << "AssertFailedException:" << ex.type << " expected:" <<
		ex.expected << " file:" << ex.file << " line:" << ex.line;
	return out;
}
bool operator == (const AssertFailedException e1, AssertFailedException e2) {
	if (e1.type != e2.type || e1.expected != e2.expected || e1.actual != e2.actual || e1.file != e2.file || e1.line != e2.line) {
		return false;
	}
	return true;
}

void assertNull(void* object, string file, long line) {
	if (object != NULL) {
		AssertFailedException ex;
		ex.type = "AssertNotNull";
		ex.expected = "not NULL";
		ex.actual = "NULL";
		ex.file = file;
		ex.line = line;
		throw ex;
	}	
}

void assertNotNull(void* object, string file, long line) {
	if (object == NULL) {
		AssertFailedException ex;
		ex.type = "AssertNotNull";
		ex.expected = "not NULL";
		ex.actual = "NULL";
		ex.file = file;
		ex.line = line;
		throw ex;
	}	
}

void assertTrue(bool value, string file, long line) {
	if (value != true) {
		AssertFailedException ex;
		ex.type = "AssertTrue";
		ex.expected = "true";
		ex.actual = "false";
		ex.file = file;
		ex.line = line;
		throw ex;
	}
}

void assertFalse(bool value, string file, long line) {
	if (value != false) {
		AssertFailedException ex;
		ex.type = "AssertFalse";
		ex.expected = "false";
		ex.actual = "true";
		ex.file = file;
		ex.line = line;
		throw ex;
	}
}

string intToString(int i) {
	stringstream out;
	out << i;
	return out.str();
}